#include "motor.h"
#include "ui_motor.h"
#include <QDebug>
#include "util.h"
Motor::Motor(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Motor)
{
    ui->setupUi(this);
}

Motor::~Motor()
{
    delete ui;
}

void Motor::on_slider_motor_speed_sliderReleased()
{
    int n = ui->slider_motor_speed->value();
    int set_speed = n*100;
    QByteArray arr_setValue = Util::get().read_json("./json_rc/motor.json", "set_speed", set_speed, true);
    int hz = n/2;
    int real_speed = 28*hz;
    ui->label_speed_value->setText(QString("motor_speed:   %1  r/min").arg(real_speed));
    emit(motor2sensor(arr_setValue, "设置速度大小"));
    qDebug()<<"motor.cpp 速度设置： "<<arr_setValue.toHex()<<"   "<<real_speed;
}

void Motor::on_button_motor_start_clicked()
{

    QByteArray arr_start = Util::get().read_json("./json_rc/motor.json", "start");
    emit(motor2sensor(arr_start, "motor.cpp:电机启动"));
    qDebug()<<"motor.cpp：电机启动 "<< arr_start.toHex();
}

void Motor::on_button_motor_stop_clicked()
{
    QByteArray arr_stop = Util::get().read_json("./json_rc/motor.json", "stop");
    emit(motor2sensor(arr_stop, "motor.cpp:电机停止"));
    qDebug()<<"motor.cpp: 电机停止"<<arr_stop.toHex();
}
